#!/usr/bin/bash
# -*- sh -*-

: << =cut

=head1 NAME

cputime - Plugin to monitor CPU usage

=head1 CONFIGURATION

No configuration

=head1 AUTHOR

Unknown author

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=cut

. $MUNIN_LIBDIR/plugins/plugin.sh

if [ "$1" = "autoconf" ]; then
	if [ "$(zonename)" != "global" ]; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	cat <<EOF
graph_title CPU usage
graph_info cpu time
graph_args --base 1000
graph_category system
graph_order sys user waitrq
graph_vlabel cpu time used (+) / waitrq (-) per \${graph_period}
sys.label sys
sys.min 0
sys.type DERIVE
sys.draw AREA
sys.cdef sys,1000000000,/
user.label user
user.min 0
user.draw STACK
user.type DERIVE
user.cdef user,1000000000,/
waitrq.label waitrq
waitrq.type DERIVE
waitrq.draw LINE1
waitrq.cdef waitrq,1000000000,/,-1,*
EOF
	exit 0
fi

kstat -p zones:*:*:nsec_sys zones:*:*:nsec_user zones:*:*:nsec_waitrq | sed 's/.*nsec_//g' | awk '{ print $1 ".value", $2 }'
